/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.snda.lidejia.jobflow.job;

import com.snda.lidejia.jobflow.exception.JobFlowException;
import com.snda.lidejia.jobflow.task.Task;
import com.snda.lidejia.jobflow.task.TaskData;
import java.util.LinkedList;
import java.util.List;

/**
 *
 * @author lidejia
 */
public class Job {

    private List<Task> tasks = new LinkedList<Task>();
    private TaskData jobInput = null;

    public Job() {
    }

    public Job(TaskData jobInput) {
        this.jobInput = jobInput;
    }

    public void addTask(Task task) {
        tasks.add(task);
    }

    public void setJobInput(TaskData jobInput) {
        this.jobInput = jobInput;
    }

    public TaskData run() throws JobFlowException {
        TaskData lastOutput = jobInput;
        for (Task task : tasks) {
            lastOutput = task.run(lastOutput);
        }
        return lastOutput;
    }
}
